/*
This file executes the regressions discussed in section 5 and outputs the
results to LaTeX tables (for use in the paper) as well as csv files.
*/

set more off

clear all

est clear

set scheme s1mono

local reps 1000	//number of bootstrap replications used in wild bootstrap 
				//procedure

use "$data/incFinalMonthlyTehsil" //use cleaned and aggregated violence data

//label variables
label variable strikes "Strikes (Tehsil)"
label variable strikesDist "Strikes"
label variable totCas "Casualties"
label variable incidents "Attacks"
label variable trtXnwa "treat\(\cdot\)nwa"
label variable mo "MO"
label variable peace "Peace"
label variable obamareview "Obamareview"
label variable haqqanipakistan "Haqqani"

drop if dist=="swa" //drop SWA from analysis

xtset tehsiln monyr

/*
Runs regressions. The formatting of the code is the same as in 
diffInDiff.do.
*/

//incidents dependent variable
xtreg incidents trtXnwa $tmFE, fe cluster(tehsiln)
eststo inc6_est1
cgmwildboot incidents trtXnwa $tehFE $tmFE, cluster(tehsiln) bootcluster(tehsiln) reps(`reps')
scalar p = e(pval)
estadd scalar wcbp = p : inc6_est1

xtreg incidents strikesDist $tehFE $tmFE, fe cluster(tehsiln)
eststo inc6_est2
cgmwildboot incidents strikesDist $tehFE $tmFE, cluster(tehsiln) bootcluster(tehsiln) reps(`reps')
scalar p = e(pval)
estadd scalar wcbp2 = p : inc6_est2

xtreg incidents trtXnwa strikesDist $tehFE $tmFE, fe cluster(tehsiln)
eststo inc6_est3
cgmwildboot incidents trtXnwa strikesDist $tehFE $tmFE, cluster(tehsiln) bootcluster(tehsiln) reps(`reps')
scalar p = e(pval)
estadd scalar wcbp = p : inc6_est3
scalar p = e(pval2)
estadd scalar wcbp2 = p : inc6_est3

//casualties dependent variable
xtreg totCas trtXnwa $tmFE, fe cluster(tehsiln)
eststo cas6_est1
cgmwildboot totCas trtXnwa $tehFE $tmFE, cluster(tehsiln) bootcluster(tehsiln) reps(`reps')
scalar p = e(pval)
estadd scalar wcbp = p : cas6_est1

xtreg totCas strikesDist $tehFE $tmFE, fe cluster(tehsiln)
eststo cas6_est2
cgmwildboot totCas strikesDist $tehFE $tmFE, cluster(tehsiln) bootcluster(tehsiln) reps(`reps')
scalar p = e(pval)
estadd scalar wcbp2 = p : cas6_est2

xtreg totCas trtXnwa strikesDist $tehFE $tmFE, fe cluster(tehsiln)
eststo cas6_est3
cgmwildboot totCas trtXnwa strikesDist $tehFE $tmFE, cluster(tehsiln) bootcluster(tehsiln) reps(`reps')
scalar p = e(pval)
estadd scalar wcbp = p : cas6_est3
scalar p = e(pval2)
estadd scalar wcbp2 = p : cas6_est3

estadd local tmFE = "X" : *
estadd local tehFE = "X" : *

//Output Table 4
esttab * using "$tables/decomp.tex", replace label se star(* 0.05) keep(trtXnwa strikesDist) scalar("wcbp WB p-value (Program)" "wcbp2 WB p-value (Strikes)" "tmFE Year FE" "tehFE Tehsil FE") title(Results Decomposition\label{tab:decomp})
	
esttab * using "$tables/decomp.csv", replace label se star(* 0.05) keep(trtXnwa strikesDist) scalar("wcbp WB p-value (Program)" "wcbp2 WB p-value (Strikes)" "tmFE Year FE" "tehFE Tehsil FE")
